package com.hdoit.kylin.logical.group.dao.impl;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Component;

import com.tennetcn.common.dao.base.IFinderExpression;
import com.tennetcn.common.dao.base.impl.SuperDao;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.FinderExpressionFactory;
import com.hdoit.kylin.logical.group.dao.IProjectDao;
import com.hdoit.kylin.logical.group.model.Project;
import com.hdoit.kylin.logical.relative.model.ProjectUser;
import com.hdoit.kylin.logical.viewmodel.project.ProjectSearch;


/**
* @author luozhicheng
* @email
* @createtime 2017年07月19日 16:03:20
* @comment
*/
@Component
public class ProjectDaoImpl extends SuperDao<Project> implements IProjectDao{
	
	@Override
	public List<Project> queryListByGroupId(String groupId){
		IFinderExpression finder = FinderExpressionFactory.createExpression();
		finder.select("project.*")		
			  .from(Project.class,"project")
			  .andWhere("project.groupId= #{groupId}")
			  .setParam("groupId", groupId);
		
		
		return queryList(finder);

	}
	
	@Override
	public int queryCountByMark(ProjectSearch search, Integer mark){
		IFinderExpression finderExpression = FinderExpressionFactory
				.createExpression();
		finderExpression.addBody("select count(1) from",Project.class)
					     .andWhere("mark = #{mark}")
						 .setParam("mark", mark);
		return queryCount(finderExpression, search);
	}
	
	@Override
	public List<Project> queryList(String loginId) {
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("project.*")
						.from(Project.class,"project")
						.leftJoin(ProjectUser.class,"pu")
						.on("project.projectId", "pu.projectId")
						.andWhere("pu.employeeId=#{userId}")
						.setParam("userId",loginId);
						
		return queryList(finderExpression);
	}

	@Override
	public List<Project> queryList(int mark, PagerModel pagerModel){
		IFinderExpression finderExpression=FinderExpressionFactory.createExpression();
		finderExpression.select("project.*")
						.from(Project.class,"project")
						.andWhere("mark=#{mark}")
						.setParam("mark",mark);
						
		return queryList(finderExpression,pagerModel);
	}
	
	@Override
	public List<String> queryProjectNameListByGroupId(String groupId){
		List<String> projectNameList = new ArrayList<String>();
		IFinderExpression finder = FinderExpressionFactory.createExpression();
		finder.select("project.projectName")		
			  .from(Project.class,"project")
			  .andWhere("project.groupId= #{groupId}")
			  .setParam("groupId", groupId);
		
		projectNameList=queryList(finder,String.class);
		return projectNameList;

	}
}
